package com.ayoka.parenting.ui.coach.sendinvitecode;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.CoachInviteCodeBean;
import com.ayoka.parenting.databinding.ActivitySendInviteCodeBinding;
import com.ayoka.parenting.mvp.MVPBaseActivity;
import com.jincp.common.model.ToolBarOptions;
import com.jincp.common.utils.Base64Utils;
import com.jincp.image.load.ImageLoader;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: SendInviteCodeActivity.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class SendInviteCodeActivity extends MVPBaseActivity<ActivitySendInviteCodeBinding, SendInviteCodeContract.View, SendInviteCodePresenter> implements SendInviteCodeContract.View {

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, SendInviteCodeActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_send_invite_code;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        ToolBarOptions options = new ToolBarOptions(R.string.send_invite_code);
        setCustomToolBar(mDataBinding.customToolbar.toolbar, options);

        if (mPresenter != null) {
            mPresenter.getInviteCodeData();
        }
    }

    @Override
    protected SendInviteCodePresenter getPresenter() {
        return new SendInviteCodePresenter();
    }

    @Override
    public void configInviteCodeData(CoachInviteCodeBean data) {
        if (data == null) return;
        try {
            byte[] decodedString = Base64Utils.decode(data.img);
            Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
            mDataBinding.ivInviteCode.setImageBitmap(decodedBitmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
